var kolom;
var typedata;

switch(type_window){
	/* Modul Supply */
	case 'dealer':
	case 'dealer_transfer':
		kolom = [
			{field:'nama_dealer',title:'Nama Dealer',width:250, halign:'center', align:'left'},
		];
		typedata = 'searchdealer';
	break;
	case 'mutasi':
		kolom = [
			{field:'no_mutasi_barang',title:'No. Mutasi',width:200, halign:'center', align:'left'},
			{field:'nama_dealer',title:'Dealer',width:200, halign:'center', align:'left'},			
		];
		typedata = 'searchmutasi';		
	break;
	case 'penerima':
	case 'pengecek':
	case 'pengirim':
		kolom = [
			{field:'nama_karyawan',title:'Nama Karyawan',width:250, halign:'center', align:'left'},
		];
		typedata = 'searchkaryawan';
	break;
	case 'barang':
		kolom = [
			{field:'nama_barang',title:'Nama Barang', width:250, halign:'center', align:'left'},
		];
		typedata = 'searchbarang';
	break;
	case 'gudang':
		kolom = [
			{field:'nama_gudang',title:'Nama Gudang', width:250, halign:'center', align:'left'},
		];
		typedata = 'searchgudang';
	break;
	case 'barang_bawah':
		kolom = [
			{field:'nama_barang',title:'Nama Barang', width:250, halign:'center', align:'left'},
		];
		typedata = 'searchbarang';
	break;
	
	/* Modul Procurement */
	case 'karyawan_proc':
		kolom = [
			{field:'nama_karyawan',title:'Nama Karyawan', width:250, halign:'center', align:'left'},
		];
		typedata = 'searchkaryawan_proc';
	break;
	case 'pemesanan_proc':
		kolom = [
			{field:'no_pemesanan',title:'No. Pemesanan', width:150, halign:'center', align:'center'},
			{field:'tgl_pemesanan',title:'Tgl. Pemesanan', width:150, halign:'center', align:'center'},
			{field:'nama_supplier',title:'Supplier', width:150, halign:'center', align:'left'},
			{field:'pemesanan_via',title:'Via', width:150, halign:'center', align:'left'},
			{field:'sistem_pengiriman',title:'Pengiriman', width:150, halign:'center', align:'left'},
		];
		typedata = 'pemesanan_proc';
	break;
	
	case 'supplier_proc':
		kolom = [
			{field:'nama_supplier',title:'Nama Supplier', width:250, halign:'center', align:'left'},
		];
		typedata = 'searchsupplier_proc';
	break;
	case 'barang_proc':
		kolom = [
			{field:'nama_barang',title:'Nama Barang', width:250, halign:'center', align:'left'},
		];
		typedata = 'searchbarang_na';
	break;
	
	case 'faktur_proc':
		kolom = [
			{field:'no_faktur_pembelian',title:'No Faktur', width:250, halign:'center', align:'left'},
			{field:'tgl_faktur',title:'Tgl Faktur', width:100, halign:'center', align:'left'},
		];
		typedata = 'faktur_proc';
	break;
	
}

$("#table_search_"+type_window).datagrid({     
	height:frmHeight-400,
	width:frmWidth-600,
	rownumbers:true,
	fit:true,
	striped:true,
	pagination:true,
	sortable:true,
	url:'home/generaldisplay/getdatawindow/'+typedata+'/',		
	nowrap: false,
	singleSelect:true,
	pageNumber:'1',
	columns:[kolom],
	queryParams:{
		parameter_data: type_getdisp
	},
	onClickRow: function(rowIndex, rowData){
		if(type_window == 'dealer'){
			$('#dealer_'+type_getdisp).val(rowData.nama_dealer);
			$('#id_dealer_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'dealer_transfer'){
			$('#dealer_transfer_'+type_getdisp).val(rowData.nama_dealer);
			$('#id_dealer_transfer_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'mutasi'){
			$('#mutasi_'+type_getdisp).val(rowData.no_mutasi_barang);
			$('#id_mutasi_'+type_getdisp).val(rowData.id);
			$('#tgl_mutasi_brg_'+type_getdisp).html(rowData.tgl_mutasi);
			$('#pngrim_brg_'+type_getdisp).html(rowData.nama_karyawan);
		}else if(type_window == 'penerima'){
			$('#penerima_'+type_getdisp).val(rowData.nama_karyawan);
			$('#id_penerima_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'pengecek'){
			$('#pengecek_'+type_getdisp).val(rowData.nama_karyawan);
			$('#id_pengecek_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'pengirim'){
			$('#pengirim_'+type_getdisp).val(rowData.nama_karyawan);
			$('#id_pengirim_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'barang'){
			$('#barang_'+type_getdisp).val(rowData.nama_barang);
			$('#id_barang_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'gudang'){
			$('#gudang_'+type_getdisp).val(rowData.nama_gudang);
			$('#id_gudang_'+type_getdisp).val(rowData.id);
		}else if(type_window == 'barang_bawah'){
			$('#dtbarang_'+type_getdisp+'_'+nomer_id).val(rowData.nama_barang);
			$('#id_barang_'+type_getdisp+'_'+nomer_id).val(rowData.id);
		}else if(type_window == 'karyawan_proc'){
			//$('#nm_karyawan').val(rowData.nama_karyawan);
			$('#id_karyawan_'+type_getdisp).val(rowData.id);
			$('#nama_karyawan_'+type_getdisp).val(rowData.nama_karyawan);
			$('#jabatan_'+type_getdisp).html(rowData.jabatan);
			$('#departemen_'+type_getdisp).html(rowData.nama_departemen);
			$('#divisi_'+type_getdisp).html(rowData.nama_divisi);
			$('#nama_dealer_'+type_getdisp).html(rowData.nama_dealer);
			$('#group_dealer_'+type_getdisp).html(rowData.nama_group_dealer);
		}else if(type_window == 'supplier_proc'){
			//$('#nm_supplier').val(rowData.nama_supplier);
			$('#kode_supplier_'+type_getdisp).val(rowData.id);
			$('#nama_supplier_'+type_getdisp).val(rowData.nama_supplier);
			$('#kota_'+type_getdisp).html("Provinsi "+rowData.nama_provinsi+" Kabupaten "+rowData.nama_kabupaten);
			$('#alamat_'+type_getdisp).html(rowData.alamat);
			$('#telp_'+type_getdisp).html(rowData.no_telp);
			$('#email_'+type_getdisp).html(rowData.email);
		}else if(type_window == 'barang_proc'){
			$('#kode_barang_'+modul+'_'+nomer_id).val(rowData.id);
			$('#kd_brg_'+modul+'_'+nomer_id).val(rowData.nama_barang);
			$('#group_na_'+modul+'_'+nomer_id).html(rowData.nama_group_barang);
			$('#kategori_na_'+modul+'_'+nomer_id).html(rowData.kategori_barang);
			$('#nama_na_'+modul+'_'+nomer_id).html(rowData.nama_barang);
			$('#merk_na_'+modul+'_'+nomer_id).html(rowData.merek_barang);
			$('#satuan_na_'+modul+'_'+nomer_id).html(rowData.satuan_barang);
			$('#harga_na_'+modul+'_'+nomer_id).html(rowData.nominal_harga);
			$('#ppn_na_'+modul+'_'+nomer_id).html(rowData.ppn);
			/*$('#tot_harga_na_'+nomer_id).html(rowData.nominal_harga);
			$('#dpp_na_'+nomer_id).html(rowData.nominal_harga);
			
			$('#harga_ppn_'+nomer_id).html(rowData.nominal_harga);
			*/
			//console.log(rowData.kategori_barang);
		}else if(type_window == 'pemesanan_proc'){
			//$('#nm_supplier').val(rowData.nama_supplier);
			$('#no_pemesanan_'+type_getdisp).val(rowData.no_pemesanan);
			$('#tbl_master_pemesananbarang_id_'+type_getdisp).val(rowData.id);
			$('#no_permintaan_'+type_getdisp).html(rowData.no_permintaan);
			$('#tgl_pesanan_'+type_getdisp).html(rowData.tgl_pemesanan);
			$('#tgl_permintaan_'+type_getdisp).html(rowData.tgl_permintaan);
			$('#group_'+type_getdisp).html(rowData.nama_group_dealer);
			$('#dealer_'+type_getdisp).html(rowData.nama_dealer);
			
			get_datapemesanan(rowData.id);
		}else if(type_window == 'faktur_proc'){
			$('#tbl_faktur_pembelian_id_'+type_getdisp).val(rowData.id);
			$('#no_faktur_'+type_getdisp).val(rowData.no_faktur_pembelian);
			$('#tgl_faktur_'+type_getdisp).html(rowData.tgl_faktur);
		}
		
		closeWindow2();
	}
});
